home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / fontdisplay_class.c next >
Encoding:
C/C++ Source or Header  |  2002-02-13  |  4.4 KB  |  146 lines

  1. #include "system_headers.h"
  2.  
  3. #define FD_EXAMPLE_TEXT "¤¢ the quick brown fox jumps over the lazy dog"
  4.  
  5. // extern void kprintf(char *, ...);
  6.  
  7. static ULONG __saveds mNew( struct IClass *cl,
  8.                             Object *obj,
  9.                             Msg msg )
  10. {
  11.     struct FontDisplayData *fdd;
  12.     struct TagItem *tags, *tag;
  13.  
  14.     if (!(obj = (Object *)DoSuperMethodA(cl, obj, msg)))
  15.         return(0);
  16.  
  17.     fdd = INST_DATA(cl, obj);
  18.  
  19.     /* parse initial taglist */
  20.  
  21.     for (tags = ((struct opSet *)msg)->ops_AttrList; tag=NextTagItem(&tags); ) {
  22.         switch (tag->ti_Tag) {
  23.             case FDATTR_Font:
  24.                 if (tag->ti_Data) fdd->fdd_Font = (struct TextFont *)tag->ti_Data;
  25.                 break;
  26.         }
  27.     }
  28.  
  29.     return (ULONG)obj;
  30. }
  31.  
  32. static ULONG __saveds mSet( struct IClass *cl,
  33.                             Object *obj,
  34.                             Msg msg )
  35. {
  36.     struct FontDisplayData *fdd = INST_DATA(cl, obj);
  37.     struct TagItem *tags, *tag;
  38.  
  39.     for (tags = ((struct opSet *)msg)->ops_AttrList; tag = NextTagItem(&tags); ) {
  40.         switch (tag->ti_Tag) {
  41.             case FDATTR_Font:
  42.                 if (tag->ti_Data) {
  43.                     fdd->fdd_Font = (struct TextFont *)tag->ti_Data;
  44.                     MUI_Redraw(obj, MADF_DRAWOBJECT); /* redraw ourselves completely */
  45.                 }
  46.                 break;
  47.         }
  48.     }
  49.  
  50.     return (DoSuperMethodA(cl,obj,msg));
  51. }
  52.  
  53.  
  54. static ULONG __saveds mGet( struct IClass *cl,
  55.                             Object *obj,
  56.                             Msg msg )
  57. {
  58.     struct FontDisplayData *fdd = INST_DATA(cl, obj);
  59.     ULONG *store = ((struct opGet *)msg)->opg_Storage;
  60.  
  61.     switch (((struct opGet *)msg)->opg_AttrID)
  62.     {
  63.         case FDATTR_Font: *store = (ULONG)fdd->fdd_Font; return (TRUE);
  64.     }
  65.  
  66.     return (DoSuperMethodA(cl, obj, msg));
  67. }
  68.  
  69.  
  70. static ULONG __saveds mAskMinMax( struct IClass *cl,
  71.                                   Object *obj,
  72.                                   struct MUIP_AskMinMax *msg )
  73. {
  74.     DoSuperMethodA(cl, obj, msg);
  75.  
  76.     msg->MinMaxInfo->MinWidth  += 100;
  77.     msg->MinMaxInfo->DefWidth  += 100;
  78.     msg->MinMaxInfo->MaxWidth  += 1000;
  79.  
  80.     msg->MinMaxInfo->MinHeight += 60;
  81.     msg->MinMaxInfo->DefHeight += 60;
  82.     msg->MinMaxInfo->MaxHeight += 60;
  83.  
  84.     return(0);
  85. }
  86.  
  87. static ULONG __saveds mDraw( struct IClass *cl,
  88.                              Object *obj,
  89.                              struct MUIP_Draw *msg )
  90. {
  91.     struct FontDisplayData *fdd = INST_DATA(cl, obj);
  92.  
  93.     // kprintf("FontDisplayClass: mDraw()\n");
  94.  
  95.     DoSuperMethodA(cl, obj, msg);
  96.  
  97.     // kprintf("FontDisplayClass: fdd_Font = %08lx\n", fdd->fdd_Font);
  98.     if (fdd->fdd_Font) {
  99.         struct Region *newRegion;
  100.  
  101.         // kprintf("FontDisplayClass: %s/%ld\n", fdd->fdd_Font->tf_Message.mn_Node.ln_Name, fdd->fdd_Font->tf_YSize);
  102.  
  103.         SetFont(_rp(obj), fdd->fdd_Font);
  104.         SetAPen(_rp(obj), 1);
  105.  
  106.         if (newRegion = NewRegion()) {
  107.             struct Rectangle rect;
  108.             struct Region *oldRegion;
  109.  
  110.             rect.MinX = _mleft(obj);
  111.             rect.MaxX = _mright(obj);
  112.             rect.MinY = _mtop(obj);
  113.             rect.MaxY = _mbottom(obj);
  114.             OrRectRegion(newRegion, &rect);
  115.  
  116.             // kprintf("FontDisplayClass: displaying in rect (%ld, %ld) - (%ld, %ld)\n", rect.MinX, rect.MinY, rect.MaxX, rect.MaxY);
  117.             oldRegion = InstallClipRegion(_window(obj)->WLayer, newRegion);
  118.             if (fdd->fdd_Font->tf_YSize > _mheight(obj)) {
  119.                 Move(_rp(obj), _mleft(obj), _mtop(obj) + fdd->fdd_Font->tf_Baseline);
  120.             } else {
  121.                 Move(_rp(obj), _mleft(obj), _mtop(obj) + ((_mheight(obj) - fdd->fdd_Font->tf_YSize) / 2) + fdd->fdd_Font->tf_Baseline);
  122.             }
  123.             Text(_rp(obj), FD_EXAMPLE_TEXT, strlen(FD_EXAMPLE_TEXT));
  124.             InstallClipRegion(_window(obj)->WLayer, oldRegion);
  125.         }
  126.     }
  127.  
  128.     return(0);
  129. }
  130.  
  131. ULONG __asm __saveds FontDisplayDispatcher( register __a0 struct IClass *cl,
  132.                                             register __a2 Object *obj,
  133.                                             register __a1 Msg msg )
  134. {
  135.     switch (msg->MethodID) {
  136.         case OM_NEW        : return (mNew      (cl, obj, (APTR)msg));
  137.         case OM_SET        : return (mSet      (cl, obj, (APTR)msg));
  138.         case OM_GET        : return (mGet      (cl, obj, (APTR)msg));
  139.         case MUIM_AskMinMax: return (mAskMinMax(cl, obj, (APTR)msg));
  140.         case MUIM_Draw     : return (mDraw     (cl, obj, (APTR)msg));
  141.     }
  142.  
  143.     return (DoSuperMethodA(cl, obj, msg));
  144. }
  145.  
  146.